package com.ycz.pattern.behaviour.iteratorpattern;

/**
 * @author yancz
 * @ClassName NameRepository
 * @description: TODO
 * @date 2023-11-28 14:52:47
 * @version: 1.0
 */
public class NameRepository implements Container {

    private String[] names = {"韩立","厉飞鱼","南宫婉","陈巧倩","文思月","墨彩环"};

    @Override
    public MyIterator getIterator() {
        return new NameIterator();
    }

    private class NameIterator implements MyIterator {

        int index;

        @Override
        public boolean hasNext() {
            return index < names.length;
        }
        @Override
        public Object next() {
            if(this.hasNext()) return names[index++];
            return null;
        }
    }
}
